home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / flicb_1.6 / flicb_1 / flicb / curses-io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-11  |  15.8 KB  |  636 lines

  1. /* Fairlight's ICB Client                                                    */
  2. /* Copyright 1994, Mark Luljak <fairlite@arcadia.aldridge.sol.net>           */
  3. /*                                                                           */
  4.  
  5.  
  6.  
  7. #include "flicb.h"
  8.  
  9. /*  Function:  [hi]output(stringer, y, x, wptr);
  10.  *  Output a [highlighted] string in the window environment.
  11.  *  Parms:  stringer = string to output
  12.  *          wptr     = pointer to window to output in
  13.  *          x, y     = x, y coordinates within window to print at
  14.  *  Return:  returns static value of zero (0)
  15.  */
  16.  
  17. int hioutput(stringer, y, x, wptr)
  18. char stringer[STRINGSIZE];
  19. int y, x;
  20. WINDOW *wptr;
  21. {
  22.      char *sptr;
  23.  
  24.      wmove(wptr, y, x);
  25.      wclrtoeol(wptr);
  26.      wstandout(wptr);
  27.      for (sptr = stringer; *sptr; sptr++) {
  28.           waddch(wptr, *sptr);
  29.           x++;
  30.           wmove(wptr,y,x);
  31.           wclrtoeol(wptr);
  32.      }
  33.      wstandend(wptr);
  34.      wrefresh(wptr);
  35.      return(0);
  36. }
  37.  
  38.  
  39. int output(stringer, y, x, wptr)
  40. char stringer[STRINGSIZE];
  41. int y, x;
  42. WINDOW *wptr;
  43. {
  44.      char *sptr;
  45.  
  46.      wmove(wptr, y, x);
  47.      wclrtoeol(wptr);
  48.      for (sptr = stringer; *sptr; sptr++) {
  49.           waddch(wptr, *sptr);
  50.           x++;
  51.           wmove(wptr,y,x);
  52.           wclrtoeol(wptr);
  53.      }
  54.      wrefresh(wptr);
  55.      return(0);
  56. }
  57.  
  58.  
  59.  
  60. int noutput(stringer, y, x, wptr)
  61. char stringer[STRINGSIZE];
  62. int y, x;
  63. WINDOW *wptr;
  64. {
  65.      char *sptr;
  66.  
  67.      wmove(wptr, y, x);
  68.      for (sptr = stringer; *sptr; sptr++) {
  69.           waddch(wptr, *sptr);
  70.           x++;
  71.           wmove(wptr,y,x);
  72.      }
  73.      return(0);
  74. }
  75.  
  76. int w_pub_output(stringer,nick, y, x, wptr,winsize,ismesg)
  77. char stringer[STRINGSIZE], nick[15];
  78. int y,x;
  79. WINDOW *wptr;
  80. int winsize,ismesg;
  81. {
  82.      int a,endy,flag=0,origx;
  83.      char totalnick[17],buffer[STRINGSIZE],bbuf[STRINGSIZE],*tmpword;
  84.      char newstring[STRINGSIZE];
  85.      char *optr,*tptr,*zptr;
  86.  
  87.      endy=y;
  88.      origx=x;
  89.      sprintf(newstring,"%s\0",stringer);
  90.      wmove(wptr, y, origx);
  91.      sprintf(totalnick,"<%s> ",nick);
  92.      for (tptr=newstring;*tptr;tptr++) {}
  93.      for (tmpword=strtok(newstring," ");tmpword;) {
  94.           #ifdef SYSLOG
  95.           openlog("flicb",LOG_PID,LOG_USER);
  96.       syslog(LOG_INFO,"nick: %s",totalnick);
  97.           #endif
  98.           if (y >= winsize) {
  99.               flag=1;
  100.               y = winsize-1;
  101.               wmove(wptr,0,0);
  102.               wdeleteln(wptr);
  103.           wmove(wptr,y,origx);
  104.               winsertln(wptr);
  105.           wmove(wptr,y,origx);
  106.               wclrtobot(wptr);
  107.               wrefresh(wptr);
  108.           }
  109.           output(totalnick,y,x,wptr);
  110.           x+=strlen(totalnick);
  111.           wmove(wptr,y,x);
  112.           sprintf(buffer,"%s",tmpword);
  113.           a=strlen(tmpword);
  114.           #ifdef SYSLOG
  115.           syslog(LOG_INFO,"tmpword: %s",tmpword);
  116.           #endif
  117.           for (;;) {
  118.                for (optr=tmpword;*optr;optr++) {}
  119.                optr++;
  120.                for (zptr=buffer;*zptr;zptr++) {}
  121.                for (;!(a+1 > (80-origx-strlen(totalnick)-3));) {
  122.                     if (*optr != ' ') { break; }
  123.                     if (*optr) {
  124.                          *zptr=*optr;
  125.                          zptr++;
  126.                          optr++;
  127.                          a++;
  128.                     } else { break; }
  129.                }
  130.                *zptr='\0';
  131.                tmpword = strtok(NULL," ");
  132.                #ifdef SYSLOG
  133.                syslog(LOG_INFO,"tmpword: %s",tmpword);
  134.                syslog(LOG_INFO,"optr: %s",optr);
  135.                #endif
  136.                if (!tmpword) {
  137.                     break;
  138.                }
  139.                if ((a+strlen(tmpword)) > (80-origx-strlen(totalnick)-3)) {
  140.                     break;
  141.                } else {
  142.                     sprintf(buffer,"%s %s",buffer,tmpword);
  143.                     a+=(strlen(tmpword)+1);
  144.                }
  145.           }
  146.           sprintf(buffer,"%s%c",buffer,NULL);
  147.           output(buffer,y,x,wptr);
  148.           y++;
  149.           x=origx;
  150.      }
  151.      x=origx;
  152.      if (alertmes == 1 && ismesg == 1) {
  153.           wmove(wptr,1,1);
  154.           waddch(wptr,'\007');
  155.           wmove(wptr,y,x);
  156.           wrefresh(wptr);
  157.           wmove(wptr,1,1);
  158.           waddch(wptr,' ');
  159.      }
  160.      wmove(wptr,y,x);
  161.      wrefresh(wptr);
  162.      #ifdef SYSLOG
  163.      closelog();
  164.      #endif 
  165.      if (flag) {
  166.           return(winsize);
  167.      } else {
  168.           return(y-endy);
  169.      }
  170. }
  171.  
  172.  
  173. int w_stat_output(stringer,nick, y, x, wptr,winsize)
  174. char stringer[STRINGSIZE], nick[15];
  175. int y,x;
  176. WINDOW *wptr;
  177. int winsize;
  178. {
  179.      int a,endy,flag=0,origx;
  180.      char totalnick[17],buffer[STRINGSIZE],bbuf[STRINGSIZE],*tmpword;
  181.      char newstring[STRINGSIZE];
  182.  
  183.      endy=y;
  184.      origx=x;
  185.      sprintf(newstring,"%s",stringer);
  186.      wmove(wptr, y, origx);
  187.      sprintf(totalnick,"[=%s=] - ",nick);
  188.      for (tmpword=strtok(newstring," ");tmpword;) {
  189.           if (y >= winsize) {
  190.               flag=1;
  191.               y = winsize-1;
  192.               wmove(wptr,0,0);
  193.               wdeleteln(wptr);
  194.               wmove(wptr, y, origx);
  195.               winsertln(wptr);
  196.               wmove(wptr, y, origx);
  197.               wclrtobot(wptr);
  198.               wrefresh(wptr);
  199.           }
  200.           output(totalnick,y,x,wptr);
  201.           x+=strlen(totalnick);
  202.           wmove(wptr,y,x);
  203.           sprintf(buffer,"%s",tmpword);
  204.           a=strlen(tmpword);
  205.           for (;;) {
  206.                tmpword = strtok(NULL," ");
  207.                if (!tmpword) {
  208.                     break;
  209.                }
  210.                if ((a+strlen(tmpword)) > (80-origx-strlen(totalnick)-3)) {
  211.                     break;
  212.                } else {
  213.                     sprintf(buffer,"%s %s",buffer,tmpword);
  214.                     a+=(strlen(tmpword)+1);
  215.                }
  216.           }
  217.           sprintf(buffer,"%s%c",buffer,NULL);
  218.           output(buffer,y,x,wptr);
  219.           y++;
  220.           x=origx;
  221.      }
  222.      x=origx;
  223.      wmove(wptr,y,x);
  224.      wrefresh(wptr);
  225.      if (flag) {
  226.           return(winsize);
  227.      } else {
  228.           return(y-endy);
  229.      }
  230. }
  231.  
  232.  
  233.  
  234.  
  235.  
  236. int w_beep_output(stringer,nick, y, x, wptr,winsize)
  237. char stringer[STRINGSIZE], nick[15];
  238. int y,x;
  239. WINDOW *wptr;
  240. int winsize;
  241. {
  242.      int a,endy,flag=0,origx;
  243.      char totalnick[17],buffer[STRINGSIZE],bbuf[STRINGSIZE],*tmpword;
  244.      char newstring[STRINGSIZE];
  245.  
  246.      endy=y;
  247.      origx=x;
  248.      sprintf(newstring,"%s sent you a beep!",stringer);
  249.      wmove(wptr, y, origx);
  250.      sprintf(totalnick,"[=BEEP=] - ");
  251.      for (tmpword=strtok(newstring," ");tmpword;) {
  252.           if (y >= winsize) {
  253.               flag=1;
  254.               y = winsize-1;
  255.               wmove(wptr,0,0);
  256.               wdeleteln(wptr);
  257.               wmove(wptr,y,origx);
  258.               winsertln(wptr);
  259.               wmove(wptr, y, origx);
  260.               wclrtobot(wptr);
  261.               wrefresh(wptr);
  262.           }
  263.           output(totalnick,y,x,wptr);
  264.           x+=strlen(totalnick);
  265.           wmove(wptr,y,x);
  266.           sprintf(buffer,"%s",tmpword);
  267.           a=strlen(tmpword);
  268.           for (;;) {
  269.                tmpword = strtok(NULL," ");
  270.                if (!tmpword) {
  271.                     break;
  272.                }
  273.                if ((a+strlen(tmpword)) > (80-origx-strlen(totalnick)-3)) {
  274.                     break;
  275.                } else {
  276.                     sprintf(buffer,"%s %s",buffer,tmpword);
  277.                     a+=(strlen(tmpword)+1);
  278.                }
  279.           }
  280.           sprintf(buffer,"%s%c",buffer,NULL);
  281.           output(buffer,y,x,wptr);
  282.           y++;
  283.           x=origx;
  284.           wmove(wptr, y, x);
  285.      }
  286.      x=origx;
  287.      wmove(wptr,1,1);
  288.      waddch(wptr,'\007');
  289.      wmove(wptr,y,x);
  290.      wrefresh(wptr);
  291.      wmove(wptr,1,1);
  292.      waddch(wptr,' ');
  293.      wmove(wptr,y,x);
  294.      wrefresh(wptr);
  295.      if (flag) {
  296.           return(winsize);
  297.      } else {
  298.           return(y-endy);
  299.      }
  300. }
  301.  
  302.  
  303. int w_ver_output(stringer,nick, y, x, wptr,winsize)
  304. char stringer[STRINGSIZE], nick[15];
  305. int y,x;
  306. WINDOW *wptr;
  307. int winsize;
  308. {
  309.      int a,endy,flag=0,origx;
  310.      char totalnick[17],buffer[STRINGSIZE],bbuf[STRINGSIZE],*tmpword;
  311.      char newstring[STRINGSIZE];
  312.  
  313.      endy=y;
  314.      origx=x;
  315.      if (y >= winsize) {
  316.          flag=1;
  317.          y = winsize-1;
  318.          wmove(wptr,0,0);
  319.          wdeleteln(wptr);
  320.          wmove(wptr, y, origx);
  321.          winsertln(wptr);
  322.          wmove(wptr, y, origx);
  323.          wclrtobot(wptr);
  324.          wrefresh(wptr); 
  325.      }
  326.      sprintf(newstring,"%s",stringer);
  327.      wmove(wptr, y, origx);
  328.      sprintf(buffer,"Connected to %s - %s",newstring,nick);
  329.      output(buffer,y,x,wptr);
  330.      y++;
  331.      wmove(wptr,y,x);
  332.      x=origx;
  333.      wmove(wptr,y,x);
  334.      wrefresh(wptr);
  335.      if (flag) {
  336.           return(winsize);
  337.      } else {
  338.           return(y-endy);
  339.      }
  340. }
  341.  
  342. int w_cmd_output(stringer,nick, y, x, wptr,winsize)
  343. char stringer[STRINGSIZE], nick[STRINGSIZE];
  344. int y,x;
  345. WINDOW *wptr;
  346. int winsize;
  347. {
  348.      int a,endy,flag=0,origx;
  349.      char totalnick[17],buffer[STRINGSIZE],bbuf[STRINGSIZE],*tmpword;
  350.      char newstring[STRINGSIZE];
  351.  
  352.      endy=y;
  353.      origx=x;
  354.      if (y >= winsize) {
  355.          flag=1;
  356.          y = winsize-1;
  357.          wmove(wptr,0,0);
  358.          wdeleteln(wptr);
  359.          wrefresh(wptr);
  360.          wmove(wptr,y,origx);
  361.          wclrtobot(wptr);
  362.      }
  363.      sprintf(newstring,"%s",stringer);
  364.      wmove(wptr, y, origx);
  365.      sprintf(totalnick,"%s",nick);
  366.      output(newstring,y,x,wptr);
  367.      y++;
  368.      x=origx;
  369.      wmove(wptr,y,x);
  370.      wrefresh(wptr);
  371.      if (flag) {
  372.           return(winsize);
  373.      } else {
  374.           return(y-endy);
  375.      }
  376. }
  377.  
  378.  
  379.  
  380. /*  Function:  center(string, row, window, flag);
  381.  *  Output centered text in a specified window at a specified row
  382.  *  Parms:  string = string to center
  383.  *          row    = row to center text in
  384.  *          window = window to center text in
  385.  *  Return:  returns static integer zero (0)
  386.  *  Depends on:  output()
  387.  */
  388.  
  389. int center(stringval, row, wptr, flag)
  390. char stringval[STRINGSIZE];
  391. int row;
  392. WINDOW *wptr;
  393. int flag;
  394. {
  395.      int pos;
  396.  
  397.      pos = ((80-(strlen(stringval))) / 2);
  398.      if (flag) {wstandout(wptr);}
  399.      noutput(stringval, row, pos, wptr);
  400.      if (flag) {wstandend(wptr);}
  401.      wrefresh(wptr);
  402.      return(0);
  403. }
  404.  
  405.  
  406.  
  407. /*  Function:  rightflush(wptr, row, column, string)
  408.  *  Output string flushed right against a given column at given row
  409.  *      in a given window
  410.  *  Parms:  string = string to output
  411.  *          column = column to flush against
  412.  *          row    = row to output in
  413.  *          wptr   = window to output in
  414.  *  Return:  returns static integer zero (0)
  415.  *  Depends on:  output()
  416.  */
  417.  
  418. rightflush(wptr, row, column, string)
  419. WINDOW *wptr;
  420. char string[STRINGSIZE];
  421. int row, column;
  422. {
  423.      int start;
  424.  
  425.      start = ((column - strlen(string) + 1));
  426.      output(string, row, start, wptr);
  427.      wrefresh(wptr);
  428.      return(0);
  429.  
  430. }
  431.  
  432.  
  433. /*  Function:  boxit(x, y, width, height, wptr)
  434.  *  Draw a box in inverse chars, char being BOXCHAR
  435.  *  Parms:  x      = starting x
  436.  *          y      = starting y
  437.  *          width  = width of box (interior width, not counting lines)
  438.  *          height = height of box (interior)
  439.  *          wptr   = window to draw box in
  440.  *  Return:  returns static integer zero (0)
  441.  */
  442.  
  443.  
  444. int boxit(x, y, width, height, wptr)
  445. int x,y,width,height;
  446. WINDOW *wptr;
  447. {
  448.      int count;
  449.  
  450.      wstandout(wptr);
  451.      for (count = 0; count < width + 2; count++) {
  452.           wmove(wptr, y - 1, x + count - 1);
  453.           waddch(wptr, (char) BOXCHAR);
  454.           wmove(wptr, y + height + 1, x + count);
  455.           waddch(wptr, (char) BOXCHAR);
  456.      }
  457.      for (count = 0; count < height + 3; count++) {
  458.           wmove(wptr, y + count - 1, x - 1);
  459.           waddch(wptr, (char) BOXCHAR);
  460.           wmove(wptr, y + count - 1, x + width + 1);
  461.           waddch(wptr, (char) BOXCHAR);
  462.      }
  463.      wstandend(wptr);
  464.      wrefresh(wptr);
  465.      return(0);
  466. }
  467.  
  468.  
  469.  
  470. /*  Function:  centerbox(arr, wptr)
  471.  *  Center text in an array of strings inside a box centered onscreen
  472.  *  Parms:  arr  = array of strings to display
  473.  *          wptr = window to display to
  474.  *  Return:  returns static integer zero (0)
  475.  */
  476.  
  477. int centerbox(arr, wptr)
  478. char *arr[];
  479. WINDOW  *wptr;
  480. {
  481.      int maxwidth, start_x, start_y, numstrings, count;
  482.  
  483.      count = 0;
  484.      maxwidth = 0;
  485.  
  486.      for (numstrings = 0; arr[numstrings]; numstrings++) {
  487.           if(arr[numstrings]) {
  488.                if (strlen(arr[numstrings]) > maxwidth) {
  489.                     maxwidth = strlen(arr[numstrings]) + 2;
  490.            }
  491.       }
  492.      }
  493.      
  494.      numstrings--;
  495.      start_x = ((80 - (maxwidth + 2)) / 2);
  496.      start_y = ((24 - (numstrings + 2)) / 2);
  497.  
  498.      boxit(start_x, start_y, maxwidth, numstrings + 2, wptr);
  499.      for (numstrings = 0; arr[numstrings]; numstrings++) {
  500.           if (arr[numstrings]) {
  501.                center(arr[numstrings], (start_y + 1 + count++), wptr, 0);
  502.       }
  503.      }
  504.      wrefresh(wptr);
  505.      return(0);
  506. }
  507.  
  508.  
  509.  
  510.  
  511. int spinner(stringer,wptr,y,invers)
  512. char *stringer;
  513. WINDOW *wptr;
  514. int y,invers;
  515. {
  516.      char *lptr,*rptr;
  517.      int dres,lnum,rnum,lpos,rpos;
  518.      float result; 
  519.  
  520.      if (invers) {
  521.           wstandout(wptr);
  522.      }
  523.      dres=strlen(stringer);
  524.      result=dres/2;
  525.      if ((result*2)!=dres) {
  526.           lptr=stringer;
  527.           rptr=stringer;
  528.           lptr+=(dres/2);
  529.           rptr+=(dres/2);
  530.           rnum=(dres/2);
  531.           lnum=(dres/2);
  532.           lpos=((80-dres)/2)+(result); 
  533.           rpos=lpos;
  534.           wmove(wptr,y,lpos);
  535.           waddch(wptr,*lptr);
  536.           lpos--;
  537.           rpos++;
  538.           lptr--;
  539.           rptr++;
  540.           for (;lnum>0;lnum--) {
  541.                wmove(wptr,y,rpos);
  542.                waddch(wptr,'/');
  543.                wmove(wptr,y,lpos);
  544.                waddch(wptr,'\\');
  545.                wrefresh(wptr);
  546.                usleep(17500);
  547.                wmove(wptr,y,rpos);
  548.                waddch(wptr,'|');
  549.                wmove(wptr,y,lpos);
  550.                waddch(wptr,'|');
  551.                wrefresh(wptr);
  552.                usleep(17500);
  553.                wmove(wptr,y,rpos);
  554.                waddch(wptr,'-');
  555.                wmove(wptr,y,lpos);
  556.                waddch(wptr,'-');
  557.                wrefresh(wptr);
  558.                usleep(17500);
  559.                wmove(wptr,y,rpos);
  560.                waddch(wptr,'\\');
  561.                wmove(wptr,y,lpos);
  562.                waddch(wptr,'/');
  563.                wrefresh(wptr);
  564.                usleep(17500);
  565.                wmove(wptr,y,lpos);
  566.                waddch(wptr,*lptr);
  567.                wmove(wptr,y,rpos);
  568.                waddch(wptr,*rptr);
  569.                wrefresh(wptr);
  570.                usleep(17500);
  571.                lpos--;
  572.                rpos++;
  573.                lptr--;
  574.                rptr++;
  575.           }
  576.      } else {
  577.           lptr=stringer;
  578.           rptr=stringer;
  579.           lptr+=(dres/2)-1;
  580.           rptr+=(dres/2)-1;
  581.           rptr++;
  582.           rnum=(dres/2)-1;
  583.           lnum=(dres/2)-1;
  584.           lpos=((80-dres)/2)+(result)-1; 
  585.           rpos=lpos+1;
  586.           wmove(wptr,y,lpos);
  587.           waddch(wptr,*lptr);
  588.           wmove(wptr,y,rpos);
  589.           waddch(wptr,*rptr);
  590.           lpos--;
  591.           rpos++;
  592.           lptr--;
  593.           rptr++;
  594.           for (;lnum>0;lnum--) {
  595.                wmove(wptr,y,rpos);
  596.                waddch(wptr,'/');
  597.                wmove(wptr,y,lpos);
  598.                waddch(wptr,'\\');
  599.                wrefresh(wptr);
  600.                usleep(17500);
  601.                wmove(wptr,y,rpos);
  602.                waddch(wptr,'|');
  603.                wmove(wptr,y,lpos);
  604.                waddch(wptr,'|');
  605.                wrefresh(wptr);
  606.                usleep(17500);
  607.                wmove(wptr,y,rpos);
  608.                waddch(wptr,'-');
  609.                wmove(wptr,y,lpos);
  610.                waddch(wptr,'-');
  611.                wrefresh(wptr);
  612.                usleep(17500);
  613.                wmove(wptr,y,rpos);
  614.                waddch(wptr,'\\');
  615.                wmove(wptr,y,lpos);
  616.                waddch(wptr,'/');
  617.                wrefresh(wptr);
  618.                usleep(17500);
  619.                wmove(wptr,y,lpos);
  620.                waddch(wptr,*lptr);
  621.                wmove(wptr,y,rpos);
  622.                waddch(wptr,*rptr);
  623.                wrefresh(wptr);
  624.                usleep(17500);
  625.                lpos--;
  626.                rpos++;
  627.                lptr--;
  628.                rptr++;
  629.           }
  630.      }
  631.      if (invers) {
  632.           wstandend(wptr);
  633.      }
  634.      return(0);
  635. }
  636.